package com.xinxin.datastructure.queue.impl;

import com.xinxin.datastructure.array.Array;
import com.xinxin.datastructure.queue.Queue;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/4/23 17:20
 */
public class ArrayQueue<E> implements Queue<E> {
    private Array<E> array;

    public ArrayQueue(int capacity) {
        array = new Array<E>(capacity);
    }

    public ArrayQueue() {
        array = new Array<E>();
    }

    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }

    @Override
    public E dequeue() {
        return array.removeFirst();
    }

    @Override
    public E getFront() {
        return array.getFirst();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    public int getCapacity() {
        return array.getCapacity();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public String toString() {
        return String.format("Queue: size = %d, capacity = %d\n", array.getSize(), array.getCapacity()) +
                "front " + array + " tail";
    }
}
